package com.xyd.process.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyd.model.process.Process;
import com.xyd.model.process.vo.ProcessQueryVO;
import com.xyd.model.process.vo.ProcessVO;
import com.xyd.process.mapper.ProcessMapper;
import com.xyd.process.service.ProcessService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.zip.ZipInputStream;

@Service
public class ProcessServiceImpl extends ServiceImpl<ProcessMapper, Process>  implements ProcessService {


    @Resource
    private ProcessMapper processMapper;

    @Autowired
    private RepositoryService repositoryService;

    @Override
    public IPage<ProcessVO> selectPage(Page<ProcessVO> page, ProcessQueryVO processQueryVo) {
        System.out.println(page);
        System.out.println(processQueryVo);
        IPage<ProcessVO> page1 = processMapper.selectPage(page, processQueryVo);
        return page1;
    }

    @Override
    public void deployByZip(String deployPath) {
        // 定义zip输入流
        InputStream inputStream = this
                .getClass()
                .getClassLoader()
                .getResourceAsStream(deployPath);
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        // 流程部署
        Deployment deployment = repositoryService.createDeployment()
                .addZipInputStream(zipInputStream)
                .deploy();
    }


}
